home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / debugger / ddd-1.000 / ddd-1 / ddd-1.4b / ddd / CompositeB.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-21  |  3.8 KB  |  166 lines

  1. // $Id: CompositeB.C,v 1.4 1995/11/21 13:49:27 zeller Exp $
  2. // Klasse CompositeBox (Implementation)
  3.  
  4. // Copyright (C) 1995 Technische Universitaet Braunschweig, Germany.
  5. // Written by Andreas Zeller (zeller@ips.cs.tu-bs.de).
  6. // 
  7. // This file is part of the DDD Library.
  8. // 
  9. // The DDD Library is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU Library General Public
  11. // License as published by the Free Software Foundation; either
  12. // version 2 of the License, or (at your option) any later version.
  13. // 
  14. // The DDD Library is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. // See the GNU Library General Public License for more details.
  18. // 
  19. // You should have received a copy of the GNU Library General Public
  20. // License along with the DDD Library -- see the file COPYING.LIB.
  21. // If not, write to the Free Software Foundation, Inc.,
  22. // 675 Mass Ave, Cambridge, MA 02139, USA.
  23. // 
  24. // DDD is the data display debugger.
  25. // For details, see the DDD World-Wide-Web page, 
  26. // `http://www.cs.tu-bs.de/softech/ddd/',
  27. // or send a mail to the DDD developers at `ddd@ips.cs.tu-bs.de'.
  28.  
  29. char CompositeBox_rcsid[] = 
  30.     "$Id: CompositeB.C,v 1.4 1995/11/21 13:49:27 zeller Exp $";
  31.  
  32. #ifdef __GNUG__
  33. #pragma implementation
  34. #endif
  35.  
  36.  
  37. #include "assert.h"
  38. #include "misc.h"
  39. #include "CompositeB.h"
  40.  
  41. DEFINE_TYPE_INFO_1(CompositeBox, Box)
  42.  
  43. // CompositeBox
  44.  
  45. void CompositeBox::grow()
  46. // vergroessert die Boxanzahl auf das Anderthalbfache
  47. {
  48.     unsigned newSize = _size + _size / 2 + 1;
  49.     Box **newBoxes = new Box* [newSize];
  50.     for (int i = 0; i < _nchildren; i++)
  51.     newBoxes[i] = boxes[i];
  52.  
  53.     delete[] boxes;
  54.     boxes = newBoxes;
  55.     _size = newSize;
  56. }
  57.  
  58. // Font propagieren
  59. void CompositeBox::newFont(const string& font)
  60. {
  61.     for (int i = 0; i < nchildren(); i++)
  62.     {
  63.     Box* child = (*this)[i];
  64.     child->newFont(font);
  65.     }
  66.     resize();
  67. }
  68.  
  69. Box *CompositeBox::resize()
  70. // Groesse neu berechnen
  71. {
  72.     for (int i = 0; i < nchildren(); i++)
  73.     {
  74.     Box* child = (*this)[i];
  75.     child->resize();
  76.     }
  77.     return this;
  78. }
  79.  
  80. // string aus Box bilden
  81. string CompositeBox::str() const
  82. {
  83.     string s("");
  84.     for (int i = 0; i < nchildren(); i++)
  85.     {
  86.     const Box* child = (*this)[i];
  87.     s += child->str();
  88.     }
  89.     return s;
  90. }
  91.  
  92. // TagBox zu Punkt p in CompositeBox suchen
  93. const TagBox *CompositeBox::findTag(const BoxPoint& p) const
  94. {
  95.     if (p != BoxPoint(-1, -1))
  96.     for (int i = 0; i < nchildren(); i++)
  97.     {
  98.         const Box *child = (*this)[i];
  99.         const TagBox *t = child->findTag(p);
  100.         if (t != 0)
  101.         return t;   // gefunden
  102.     }
  103.     return 0; // nicht gefunden
  104. }
  105.  
  106. // MatchBoxes zaehlen
  107. void CompositeBox::countMatchBoxes(int instances[]) const
  108. {
  109.     for (int i = 0; i < nchildren(); i++)
  110.     {
  111.     const Box *child = (*this)[i];
  112.     child->countMatchBoxes(instances);
  113.     }
  114. }
  115.  
  116. // Auf Gleichheit pruefen
  117. bool CompositeBox::matches (const Box &b, const Box *) const
  118. {
  119.     // Groesse und BoxExtend nicht vergleichen,
  120.     // da MatchBoxen die Groesse 0 haben
  121.     if (strcmp(type(), b.type()))
  122.     return false;
  123.  
  124.     CompositeBox *c = (CompositeBox *)&b;   // dirty trick
  125.     if (nchildren() != c->nchildren())
  126.     return false;
  127.  
  128.     for (int i = 0; i < nchildren(); i++)
  129.     if (*((*this)[i]) != *((*c)[i]))
  130.         return false;
  131.  
  132.     return true;
  133. }
  134.  
  135. // Alignment ausgeben
  136. void CompositeBox::dumpComposite(ostream& s, 
  137.                  char *sep, char *head, char *tail) const
  138. {
  139.     s << head;
  140.     for (int i = 0; i < nchildren(); i++)
  141.     {
  142.     const Box* child = (*this)[i];
  143.     if (i > 0)
  144.         s << sep;
  145.     s << *child;
  146.     }
  147.     s << tail;
  148. }
  149.  
  150.  
  151. bool CompositeBox::OK() const
  152. // Pruefen, ob alles in Ordnung
  153. {
  154.     assert (boxes != 0);
  155.     assert (_nchildren >= 0);
  156.     assert (_size >= 0);
  157.     assert (_nchildren <= _size);
  158.  
  159.     for (int i = 0; i < _nchildren; i++)
  160.     assert (boxes[i]->OK());
  161.  
  162.     assert (Box::OK());
  163.  
  164.     return true;
  165. }
  166.